<?php

namespace app\courier\controller;

use app\logic\Login as LogicLogin;

class Login extends Common
{
    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 快捷登录(手机号注册) \n
     * URI : /courier/in.login
     * @param :
     *  name    | type   | null | description
     * ---------|--------|------|-------------
     *  mobile  | string | 必填 | 手机号码
     *  passKey | string | 必填 | 发送短信时返回的key
     *  code    | string | 必填 | 验证码
     *
     * @return :
     *  name     | type   | description
     * ----------|--------|-------------
     *  passport | string | 用户passport
     *
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function quickRegistration()
    {
        $str_mobile = $this->_getContentParams('mobile');

        $str_verify_code = $this->_getContentParams('code');

        $str_pass_key = $this->_getContentParams('passKey');    //发送短信时返回的key

        $obj = new LogicLogin($this->str_module_name);

        $obj->registerOrMobileIdentifyingCodeLogin($str_mobile, $str_verify_code, $str_pass_key, $this->_getParams('platform'));
    }

    /**
     * 账号注册(手机号为账号注册) \n
     * URI : /courier/in.account.register
     * @param :
     *  name     | type   | null | description
     * ----------|--------|------|-------------
     *  mobile   | string | 必填 | 登录的手机号码
     *  passKey  | string | 必填 | 验证密钥
     *  code     | string | 必填 | 短信验证码(4位数字)
     *  password | string | 必填 | 密码
     *
     * @return :
     *  name     | type   | description
     * ----------|--------|-------------
     *  passport | string | 用户passport
     *
     */
    public function accountReg()
    {
        $str_mobile = $this->_getContentParams('mobile');

        $str_verify_code = $this->_getContentParams('code');

        $str_password = $this->_getContentParams('password', 'false'); // 密码

        $str_pass_key = $this->_getContentParams('passKey');    //发送短信时返回的key

        $obj = new LogicLogin($this->str_module_name);

        $obj->registerOrMobileIdentifyingCodeLogin($str_mobile, $str_verify_code, $str_pass_key, $this->_getParams('platform'), $str_password);
    }

    /**
     * 用户手机短信验证码登录 \n
     * URI : /courier/in.sms.login
     * @param :
     *  name    | type   | null | description
     * ---------|--------|------|-------------
     *  mobile  | string | 必填 | 登录的手机号码
     *  passKey | string | 必填 | 验证密钥
     *  code    | string | 必填 | 短信验证码(4位数字)
     *
     * @return
     *  name     | type   | description
     * ----------|--------|-------------
     *  passport | string | 用户passport
     *
     */
    public function smsLogin()
    {
        $str_mobile = $this->_getContentParams('mobile');

        $str_verify_code = $this->_getContentParams('code');

        $str_pass_key = $this->_getContentParams('passKey');    //发送短信时返回的key

        $obj = new LogicLogin($this->str_module_name);

        $obj->registerOrMobileIdentifyingCodeLogin($str_mobile, $str_verify_code, $str_pass_key, $this->_getParams('platform'));
    }

    /**
     * 用户密码登录 \n
     * URI : /courier/in.account.login
     * @param :
     *  name     | type   | null | description
     * ----------|--------|------|-------------
     *  mobile   | string | 必填 | 登录的手机号码
     *  password | string | 必填 | 登录密码
     *
     * @return
     *  name     | type   | description
     * ----------|--------|-------------
     *  passport | string | 用户passport
     *
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function accountLogin()
    {
        $str_mobile = $this->_getContentParams('mobile');

        $str_password = $this->_getContentParams('password');

        $obj = new LogicLogin($this->str_module_name);

        $obj->mobilePasswordLogin($str_mobile, $str_password, $this->_getParams('platform'));
    }

    /**
     * 忘记密码-手机号校验 \n
     * URI : /courier/in.mobile.check
     * @param :
     *  name    | type   | null | description
     * ---------|--------|------|-------------
     *  mobile  | string | 必填 | 手机号码
     *  passKey | string | 必填 | 发送短信时返回的key
     *  code    | string | 必填 | 验证码
     *
     * @return
     *  name    | type | description
     * ---------|------|-------------
     *  ------  | ---- | 无
     *
     */
    public function mobileCheck()
    {
        $str_mobile = $this->_getContentParams('mobile');

        $str_verify_code = $this->_getContentParams('code');

        $str_pass_key = $this->_getContentParams('passKey');

        $obj = new LogicLogin($this->str_module_name);

        $obj->forgetPasswordToCheckMobile($str_mobile, $str_verify_code, $str_pass_key);
    }

    /**
     * 重置密码 \n
     * URI : /courier/in.reset.pwd
     * @param :
     *  name        | type   | null | description
     * -------------|--------|------|-------------
     *  password    | string | 必填 | 新密码
     *  key         | string | 必填 | 密钥
     *
     * @return
     *  name   | type | description
     * --------|------|-------------
     *  ------ | ---- | 无
     *
     */
    public function resetPwd()
    {
        $str_password = $this->_getContentParams('password'); // 密码

        $str_key = $this->_getContentParams('key'); // 密码

        $obj = new LogicLogin($this->str_module_name);

        $obj->forgetPasswordToResetPassword($str_password, $str_key, $this->_getParams('platform'));
    }
}
